package com.aspose.cells;

import java.util.ArrayList;

class ztk {
   private zbqg a = null;
   private zok b = null;

   ztk(zok var1, zbqg var2) {
      this.b = var1;
      this.a = var2;
   }

   void a(zcfx var1) throws Exception {
      var1.b(true);
      var1.b("externalLink");
      var1.a("xmlns", zase.c);
      if (this.a.a() == 0) {
         this.b(var1);
      } else if (this.a.a() == 3) {
         this.f(var1);
      } else {
         if (this.a.a() != 4) {
            throw new CellsException(6, "Invalid SupBook Type " + this.a.a());
         }

         this.h(var1);
      }

      var1.b();
      var1.d();
      var1.e();
   }

   private void b(zcfx var1) throws Exception {
      var1.b("externalBook");
      var1.a("xmlns", "r", (String)null, "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
      var1.a("r:id", "rId1");
      this.d(var1);
      this.e(var1);
      this.c(var1);
      var1.b();
   }

   private void c(zcfx var1) throws Exception {
      String[] var2 = this.a.c();
      if (var2 != null && var2.length != 0) {
         int var3 = var2.length;
         boolean var4 = false;

         int var5;
         zut var6;
         for(var5 = 0; var5 < var3; ++var5) {
            var6 = this.a.c(var2[var5]);
            if (var6 != null) {
               var4 = true;
               break;
            }
         }

         if (var4) {
            var1.b("sheetDataSet");

            for(var5 = 0; var5 < var3; ++var5) {
               var6 = this.a.c(var2[var5]);
               if (var6 != null) {
                  var1.b("sheetData");
                  var1.a("sheetId", zase.y(var5));
                  if (var6.b != null) {
                     Object var7 = var6.b.a(3);
                     if (var7 != null) {
                        var1.a("refreshError", (String)var7);
                     }
                  }

                  if (var6.e()) {
                     ArrayList var19 = var6.a;
                     int var8 = var19.size();

                     for(int var9 = 0; var9 < var8; ++var9) {
                        zuq var10 = (zuq)var19.get(var9);
                        var1.b("row");
                        var1.a("r", zase.y(var10.a() + 1));
                        if (var10.d()) {
                           ArrayList var11 = var10.f();
                           int var12 = var11.size();

                           for(int var13 = 0; var13 < var12; ++var13) {
                              zum var14 = (zum)var11.get(var13);
                              var1.b("cell");
                              var1.a("r", CellsHelper.cellIndexToName(var10.a(), var14.a));
                              String var15 = null;
                              String var16 = null;
                              String[] var17 = new String[]{var15};
                              String[] var18 = new String[]{var16};
                              this.a(var14, var17, var18);
                              var15 = var17[0];
                              var16 = var18[0];
                              if (!"n".equals(var15)) {
                                 var1.a("t", var15);
                              }

                              var1.b("v", var16);
                              var1.b();
                           }
                        }

                        var1.b();
                     }
                  }

                  var1.b();
               }
            }

            var1.b();
         }
      }
   }

   private void a(zum var1, String[] var2, String[] var3) {
      Object var4 = var1.b;
      switch(var1.a()) {
      case 0:
         var2[0] = "b";
         var3[0] = (Boolean)var4 ? "1" : "0";
         break;
      case 1:
      case 4:
         var2[0] = "n";
         var3[0] = zase.b((Double)var4);
         break;
      case 2:
         var2[0] = "e";
         var3[0] = zsk.a((zst)var4);
         break;
      case 3:
      default:
         var2[0] = "str";
         var3[0] = com.aspose.cells.b.a.zr.a(var4);
         break;
      case 5:
         var2[0] = "str";
         var3[0] = (String)var4;
      }

   }

   private void d(zcfx var1) throws Exception {
      String[] var2 = this.a.c();
      if (var2 != null && var2.length != 0) {
         var1.b("sheetNames");

         for(int var3 = 0; var3 < var2.length; ++var3) {
            String var4 = var2[var3];
            var1.b("sheetName");
            var1.a("val", var4);
            var1.b();
         }

         var1.b();
      }
   }

   private void e(zcfx var1) throws Exception {
      ArrayList var2 = this.a.b();
      if (var2.size() != 0) {
         var1.b("definedNames");

         for(int var3 = 0; var3 < var2.size(); ++var3) {
            zuk var4 = (zuk)var2.get(var3);
            var1.b("definedName");
            var1.a("name", var4.e());
            if (var4.d() < 65535 && var4.d() > 0) {
               var1.a("sheetId", zase.y(var4.d() - 1));
            }

            String var5 = var4.a(this.b.a.getWorksheets());
            if (var5 != null && !"".equals(var5)) {
               var1.a("refersTo", var5);
            }

            var1.b();
         }

         var1.b();
      }
   }

   private void f(zcfx var1) throws Exception {
      var1.b("ddeLink");
      String var2 = null;
      String var3 = null;
      String[] var4 = new String[]{var2};
      String[] var5 = new String[]{var3};
      this.a.a(var4, var5);
      var2 = var4[0];
      var3 = var5[0];
      var1.a("xmlns", "r", (String)null, "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
      var1.a("ddeService", var2);
      var1.a("ddeTopic", var3);
      this.g(var1);
      var1.b();
   }

   private void g(zcfx var1) throws Exception {
      ArrayList var2 = this.a.b();
      if (var2.size() != 0) {
         var1.b("ddeItems");

         for(int var3 = 0; var3 < var2.size(); ++var3) {
            zuk var4 = (zuk)var2.get(var3);
            var1.b("ddeItem");
            var1.a("name", var4.e());
            if (var4.j()) {
               var1.a("ole", "1");
            }

            if (var4.k()) {
               var1.a("advise", "1");
            }

            var1.b();
         }

         var1.b();
      }
   }

   private void h(zcfx var1) throws Exception {
      var1.b("oleLink");
      String var2 = null;
      String var3 = null;
      String[] var4 = new String[]{var2};
      String[] var5 = new String[]{var3};
      this.a.a(var4, var5);
      var2 = var4[0];
      var3 = var5[0];
      var1.a("xmlns", "r", (String)null, "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
      var1.a("r:id", "rId1");
      var1.a("progId", var2);
      this.i(var1);
      var1.b();
   }

   private void i(zcfx var1) throws Exception {
      ArrayList var2 = this.a.b();
      if (var2.size() != 0) {
         var1.b("oleItems");

         for(int var3 = 0; var3 < var2.size(); ++var3) {
            zuk var4 = (zuk)var2.get(var3);
            var1.b("oleItem");
            var1.a("name", var4.e());
            if (var4.k()) {
               var1.a("advise", "1");
            }

            if (var4.l()) {
               var1.a("preferPic", "1");
            }

            var1.b();
         }

         var1.b();
      }
   }
}
